package com.fourthGroup.service.fallback;

import com.fourthGroup.model.Product;
import com.fourthGroup.service.ProductServiceFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ProductServiceFallbackFactory implements FallbackFactory<ProductServiceFeign> {
    @Override
    public ProductServiceFeign create(Throwable cause) {
        return new ProductServiceFeign(){
            @Override
            public Product queryProductById(Integer pid) {
                log.error("{}", cause);
                Product product = new Product();
                product.setPid(-1);
                product.setPname("下单失败，商品微服务不可用（FallbackFactory方式）");
                return product;
            }
        };


    }
}
